<table id="basket_for_order" border="0" cellspacing="0" cellpadding="0">
<tr style="color: #B9BBBD;">
	<td>Товар</td>
	<td>Количество</td>
	<td>Стоимость</td>
	<td>Сумма</td>
	<td>&nbsp;</td>
</tr>
<?php if (!empty($products)): 
		foreach ($products as $product):?>
<tr>
	<td>
<?php $file_path = glob(STATICROOT."images/models/{$product['id']}_*.*", GLOB_BRACE);  $path = basename($file_path[0]); ?>		
		<img width='120' height='120' src="<?=STATIC_URL?>images/models/<?=$path?>" title="<?=$product['category_id']?>:&nbsp;<?=$product['ru_name']?>" border="0" /><br><br>
		<span class="grey"><?=$product['ru_name']?>&nbsp;<?=$product['code']?></span>
	</td>
	<td>
		<input name="amount_of_position" type="text" pr_id="<?=$product['id']?>" pr_price="<?=$product['price']?>" value="<?=$_SESSION['basket']['order'][$product['id']]?>" />
	</td>
	<td>
		<p name="price_of_position"><?=$product['price']?>&nbsp;грн</p>
	</td>
	<td>
		<p name="totalcost_of_position"><span><?=$_SESSION['basket']['order'][$product['id']]*$product['price']?></span></p>&nbsp;грн</td>
	<td>
		<img src="<?=STATIC_URL?>images/trash.png" pr_id="<?=$product['id']?>" pr_price="<?=$product['price']?>" name='delete' alt="Удалить" title="Удалить" border="0" />
	</td>
</tr>
<?php endforeach; endif; ?>
<tr>
	<td colspan="3">Общая сумма</td>
	<td id="total_price">
		<span><?=$_SESSION['basket']['total_price']?></span>&nbsp;грн<br>
	</td>
	<td>&nbsp;</td>													
<tr>
<!-- tr>
	<td colspan="4" align="right">
		<button name='makeorder' style="font-size: 0.98em;">Сделать заказ</button>
	</td>
	<td>&nbsp;</td>													
<tr-->
</table>
<script type="text/javascript">
	$(document).ready(function()
		{ 
			var timeout_id;
			var object;
			
			function recalculate_order() {
					$.getJSON("<?=SCRIPTURL?>index.php",
							{ 
		                        'product_id': 	$(object).attr("pr_id"),
		                        'product_price': $(object).attr("pr_price"),
		                        'product_amount': $(object).val(),
		                        'calculate_basket': 	'TRUE'
							}, 
							function(data) {
								$('#total_price span').html(data['total_price']);
								$('#basket_total_amount span').html(data['total_amount']);
								$('#basket_total_price span').html(data['total_price']);
							});
					
					var total = $(object).attr("pr_price") * $(object).val();
					$(object).parent().siblings().children("p[name='totalcost_of_position']").html(total+ '&nbsp;грн');
				}
				
			$("input[name='amount_of_position']").keypress(function(){
				if (timeout_id != '') clearTimeout(timeout_id);
				object = this;
				timeout_id = setTimeout(function() { recalculate_order(this) }, 1500);
			});

			$("img[name='delete']").attr('style', 'cursor: pointer;').click(function(){
				object = this;
				$.getJSON("<?=SCRIPTURL?>index.php",
						{ 
	                        'product_id': 	$(this).attr("pr_id"),
	                        'product_price': $(this).attr("pr_price"),
	                        'delete_product': 	'TRUE'
						}, 
						function(data) {
							$(object).parent().parent().remove();
							$('#total_price span').html(data['total_price']);
							$('#basket_total_amount span').html(data['total_amount']);
							$('#basket_total_price span').html(data['total_price']);
						});
			});
		});
</script>